#ifndef COMBINATION_Q_S
#define COMBINATION_Q_S
#pragma once
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
// 在函数中填入对应的数字进行对比
class CombinationSolution {
public:
    int N;// the size of N
    int R;
    CombinationSolution(int n, int r) :N(n), R(r) {};

    vector<int> index2vec(int index) {
        vector<int> ans;
        return ans;
    }

    int vector2index(vector<int> comb) {
        return -1;
    }
};


class CombinationQuestions {
public:
    queue<int> answers;//代表组合对应的index
    queue<vector<int>> questions;//代表组合的所有元素
    int N, R;
    CombinationQuestions(int n, int r) :N(n), R(r) {
        /*create_questions();*/
    }
    void help(vector<int> cur, int& c, int k) {
        if (cur.size() == R) {
            answers.push(c);
            c++;
            questions.push(cur);
            return;
        }
        for (int i = k; i <= N - R + cur.size() + 1; i++) {
            cur.push_back(i);
            help(cur, c, i + 1);
            cur.pop_back();
        }
    }
    //用于创建所有的组合和排序
    void create_all_combination() {
        int start = 0;
        vector<int> k;
        help(k, start, 1);
    }
    void create_questions() {
        //这里可以根据个人的喜好去创建初始化的答案和结果,请个人选择进行初始化
        create_all_combination();
    }
    //用于创建一个的index对应combination的对
    void add_one_question_ans(vector<int>q, int a) {
        answers.push(a);
        questions.push(q);
    }

    bool justify(CombinationSolution s) {
        int id = answers.front(); answers.pop();
        vector<int> comb = questions.front(); questions.pop();

        vector<int> exp = s.index2vec(id);

        if (!justify_two_vec(exp, comb)) {
            cout << "the solution id2vetor is not true, the id is:" << id << endl << "exp: ";
            for (int i : comb)cout << i << " ";
            cout << endl << "get: ";
            for (int i : exp)cout << i << " ";
            cout << endl;
            return false;
        }
        int res = s.vector2index(comb);
        if (res != id) {
            cout << "cur index is: ";
            for (int i : comb) {
                cout << i << " ";
            }
            cout << "the solution vector2idex is not true" << endl;
            cout << "expected id: " << id << ", but get the res: " << res << endl;
            return false;
        }
        return true;
    }

    bool justify_two_vec(vector<int>& a, vector<int>& b) {
        int sz = a.size();
        for (int i = 0; i < sz; i++) {
            if (a[i] != b[i])return false;
        }
        return true;
    }

    bool empty() {
        return answers.empty();
    }
};

#endif